#!/usr/lib
import re

class Color():
	none = "\033[0m"
	red = "\033[31m"
	magenta = "\033[95m"
	yellow = "\033[33m"
	cyan = "\033[36m"
	blue = "\033[94m"
	green = "\033[92m"
	graybk = "\033[100m"

color=Color()

def comment(sc,tok):
	return color.blue+tok

def identifier(sc,tok):
	return color.none+tok

def keyword(sc,tok):
	return color.yellow+tok

def operator(sc,tok):
	return color.red+tok

def spacing(sc,tok):
	return color.graybk+tok+color.none

def text(sc,tok):
	return color.magenta+tok

def number(sc,tok):
	return color.green+tok

parser = re.Scanner([
	(r"[0-9]+",number),
	(r"#.*\n",comment),
	(r"r?'(.*[^\\])?'",text),
	(r'r?"(.*[^\\])?"',text),
	(r"(import|class|def|return|if|for|while|yield)",keyword),
	(r"[=+\-*/><\(\)\[\]:,.]=?",operator),
	(r"[a-zA-Z_][a-zA-Z0-9]*",identifier),
	(r"\s*",spacing),
])

text = open("autoscanner.py","r").read()

tokens,rest = parser.scan(text)

print "".join(tokens)
if len(rest)>0:
	print "REST:"+color.none,rest
